/*
 * Copyright (c) zhg2yqq.com Corp.
 * All Rights Reserved.
 */
package com.zhg2yqq.wheels.mvc.plugin;

import java.sql.Statement;

import org.apache.ibatis.executor.resultset.ResultSetHandler;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;

import com.zhg2yqq.wheels.mvc.util.FieldEncryptUtil;

/**
 * 注解字段解密
 *
 * @author zhg2yqq, 2022年12月3日
 * @version zhg2yqq v1.0
 */
@Intercepts({@Signature(type = ResultSetHandler.class, method = "handleResultSets", args = {
        Statement.class}),})
public class FieldDecryptInterceptor implements Interceptor {
    private String encryptKey;

    public FieldDecryptInterceptor() {
    }

    public FieldDecryptInterceptor(String encryptKey) {
        this.encryptKey = encryptKey;
    }

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        Object result = invocation.proceed();
        FieldEncryptUtil.decryptField(encryptKey, result);
        return result;
    }
}
